package chuyentrung.racehorses;

import android.app.Activity;
import android.graphics.Typeface;
import chuyentrung.racehorses.framework.Audio;
import chuyentrung.racehorses.framework.Music;
import chuyentrung.racehorses.framework.Sound;
import chuyentrung.racehorses.framework.gl.Animation;
import chuyentrung.racehorses.framework.gl.Font;
import chuyentrung.racehorses.framework.gl.Texture;
import chuyentrung.racehorses.framework.gl.TextureRegion;
import chuyentrung.racehorses.framework.impl.AndroidAudio;
import chuyentrung.racehorses.framework.impl.GLGame;

public class Assets {
	public static int HORIZON_LEFT = 0;
	public static int HORIZON_RIGHT = 1;
	public static int UP = 3;
	public static int DOWN = 3;

	public static enum TypeMusic {
		InGame, OutGame, Winner
	}

	public static enum TypeSound {
		Click, Toss, Move, Attack
	}

	public static Texture background;
	public static TextureRegion bgPlay, bgBar;

	public static Texture horse;
	public static Animation[] horseRun;
	public static TextureRegion[] horseStop;

	public static Texture items;
	public static TextureRegion pauseMenu;
	public static TextureRegion ready;
	public static TextureRegion gameOver;
	public static TextureRegion win;
	public static TextureRegion soundOn;
	public static TextureRegion soundOff;
	public static TextureRegion one, two, three, four, five, six;
	public static Animation dice;

	public static Font font;

	public static Music musicOutGame;
	public static Music musicInGame;
	public static Music musicWinner;
	public static Music music;
	
	public static Sound clickSnd;
	public static Sound tossDiceSnd;
	public static Sound moveSnd;
	public static Sound atkSnd;

	public static Typeface tfRegular;

	public static void loadAtPlay(GLGame game) {
		background = new Texture(game, "background.png");
		bgPlay = new TextureRegion(background, 0, 0, 772, 540);
		bgBar = new TextureRegion(background, 772, 0, 188, 540);

		items = new Texture(game, "items.png");
		ready = new TextureRegion(items, 780, 80, 342, 102);
		gameOver = new TextureRegion(items, 764, 0, 454, 75);
		win = new TextureRegion(items, 14, 540, 374, 202);

		horseRun = new Animation[4];
		horseStop = new TextureRegion[4];
		
		horseStop[HORIZON_LEFT] = new TextureRegion(items, 480, 318, 121, 106);
		horseStop[HORIZON_RIGHT] = new TextureRegion(items, 480, 424, 121, 100);
		horseStop[UP] = new TextureRegion(items, 480, 524, 121, 114);
		horseStop[DOWN] = new TextureRegion(items, 601, 204, 121, 112);

		horseRun[HORIZON_LEFT] = new Animation(0.2f, new TextureRegion(items,
				480, 318, 121, 106), new TextureRegion(items, 601, 318, 121, 106),
				new TextureRegion(items, 722, 318, 121, 106), new TextureRegion(
						items, 843, 318, 121, 106));
		horseRun[HORIZON_RIGHT] = new Animation(0.2f, new TextureRegion(items,
				480, 424, 121, 100), new TextureRegion(items, 601, 424, 121, 100),
				new TextureRegion(items, 722, 424, 121, 100), new TextureRegion(
						items, 843, 424, 121, 100));
		horseRun[UP] = new Animation(0.2f, new TextureRegion(items, 480, 524,
				121, 114), new TextureRegion(items, 601, 524, 121, 114),
				new TextureRegion(items, 722, 524, 121, 114), new TextureRegion(
						items, 843, 524, 121, 114));
		horseRun[DOWN] = new Animation(0.2f, new TextureRegion(items, 480, 204,
				121, 114), new TextureRegion(items, 601, 204, 121, 112),
				new TextureRegion(items, 722, 204, 121, 114),
				new TextureRegion(items, 843, 204, 121, 114));

		/*horse = new Texture(game, "horse_red.png");
		horseRun = new Animation(0.2f, new TextureRegion(horse, 0, 0, 64, 64),
				new TextureRegion(horse, 64, 0, 64, 64), new TextureRegion(
						horse, 128, 0, 64, 64), new TextureRegion(horse, 192,
						0, 64, 64));*/
		one = new TextureRegion(items, 0, 206, 158, 161);
		two = new TextureRegion(items, 158, 206, 158, 161);
		three = new TextureRegion(items, 316, 206, 146, 161);
		four = new TextureRegion(items, 0, 367, 158, 165);
		five = new TextureRegion(items, 158, 367, 158, 165);
		six = new TextureRegion(items, 316, 367, 146, 165);
		dice = new Animation(0.2f, one, three, two, six, four, five);

		musicWinner = game.getAudio().newMusic("music.mp3");
		musicWinner.setLooping(false);
		musicWinner.setVolume(0.5f);

		musicInGame = game.getAudio().newMusic("musicInGame.mp3");
		musicInGame.setLooping(true);
		musicInGame.setVolume(0.5f);
		if (GamePreferences.musicEnabled)
			musicInGame.play();

		moveSnd = game.getAudio().newSound("gallop.ogg");
		atkSnd = game.getAudio().newSound("horse_neigh.ogg");
	}

	public static void loadAtBegin(Activity act) {
		tfRegular = Typeface.createFromAsset(act.getAssets(),
				"fonts/VNI-Truck.ttf");

		Audio audio = new AndroidAudio(act);

		musicOutGame = audio.newMusic("music.mp3");
		musicOutGame.setLooping(true);
		musicOutGame.setVolume(0.5f);
		music = musicOutGame;

		clickSnd = audio.newSound("click.ogg");
	}

	public static void reload() {
        background.reload();
        items.reload();
        if(GamePreferences.musicEnabled)
            musicInGame.play();
    }

	public static void playSound(Sound sound) {
		if (GamePreferences.soundEnabled)
			sound.play(1);
	}

	public static void playMusic() {
		if (GamePreferences.musicEnabled)
			music.play();
	}		
		
}
